#
# python-ebay - A python implementation of IContact API 2.0
# Copyright (c) 2011 Alvin Delagon (http://www.alvinatorsplayground.blogspot.com/)
# All rights reserved.
#

from errors import EbayServerNotFound
from base import BaseAPI, EbayResponse


class FindingAPI(BaseAPI):

    def __init__(self, url, appId, globalId,
                 format="JSON", version="1.0.0"):
        self.url = url
        self.appId = appId
        self.globalId = globalId
        self.format = format
        self.version = version
        BaseAPI.__init__(self)

    def getSTParams(self, optName):
        return {'OPERATION-NAME': optName,
                'SERVICE-VERSION': self.version,
                'SECURITY-APPNAME': self.appId,
                'GLOBAL-ID': self.globalId,
                'RESPONSE-DATA-FORMAT': self.format}

    def searchByKeywords(self, keywords, pagination=None):
        params = self.getSTParams("findItemsByKeywords")
        params['keywords'] = keywords

        if pagination:
            params['paginationInput.entriesPerPage'] = pagination
        
        return self.callRemote(self.url, "GET", options=params)
